package com.ywx.yypicturebackend.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ywx.yypicturebackend.api.aliyunai.model.CreateOutPaintingTaskResponse;
import com.ywx.yypicturebackend.model.dto.picture.*;
import com.ywx.yypicturebackend.model.entity.Picture;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ywx.yypicturebackend.model.entity.User;
import com.ywx.yypicturebackend.model.vo.LoginUserVO;
import com.ywx.yypicturebackend.model.vo.PictureVO;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* @author ywx
* @description 针对表【picture(图片)】的数据库操作Service
* @createDate 2025-05-13 19:30:38
*/
public interface PictureService extends IService<Picture> {


    /**
     * 文件上传
     * @param inputSource  前端传来的文件或URL
     * @param pictureUploadRequest 判断是新上传还是修改
     * @param loginUser 当前登录用户
     * @return PictureVO
     */
    PictureVO uploadPicture(Object inputSource,
                            PictureUploadRequest pictureUploadRequest,
                            User loginUser);

    /**
     * 获取图片分页查询条件对象
     * @param pictureQueryRequest
     * @return
     */
    QueryWrapper<Picture> getQueryWrapper(PictureQueryRequest pictureQueryRequest);


    /**
     * 获取单个图片的封装
     * @param picture
     * @param request
     * @return
     */
    PictureVO getPictureVO(Picture picture, HttpServletRequest request);

    /**
     * 将图片分页结果转换成图片封装类的分页结果
     * @param picturePage
     * @param request
     * @return
     */
    public Page<PictureVO> getPictureVOPage(Page<Picture> picturePage, HttpServletRequest request);


    /**
     * 获取空间中的所有图片
     * @param spaceId
     * @return
     */
    public List<Picture> getPicturesBySpaceId(Long spaceId);

    /**
     * 图片数据校验,用于图片更新和修改时进行判断
     * @param picture
     */
    public void validPicture(Picture picture);

    /**
     * 图片审核
     * @param loginUser
     */
     void doPictureReview(PictureReviewRequest pictureReviewRequest,User loginUser);


    /**
     * 自动填充审核参数
     * 在上传,用户编辑,管理员更新图片时需要将审核状态自动设置为未审核,或者管理员自动过审
     * @param picture
     * @param loginUser
     */
    void fileReviewParams(Picture picture, User loginUser);


    /**
     * 批量抓取和创建图片
     *
     * @param pictureUploadByBatchRequest
     * @param loginUser
     * @return 成功创建的图片数
     */
    Integer uploadPictureByBatch(
            PictureUploadByBatchRequest pictureUploadByBatchRequest,
            User loginUser
    );


    /**
     * 用户编辑图片
     * @param pictureEditRequest
     * @param loginUser
     */
    void editPicture(PictureEditRequest pictureEditRequest,User loginUser);



    /**
     * 删除图片
     * @param loginUser
     * @param pictureId
     */
    void deletePicture(User loginUser,Long pictureId);


    /**
     * 清理图片
     * @param picture
     */
    void clearPictureFile(Picture picture);


    /**
     * 校验当前用户是否有权限操作该图片
     * @param picture
     * @param loginUser
     * @return
     */
    void checkPictureAuth(Picture picture,User loginUser);

    /**
     * 根据颜色搜索相似图片
     * @param spaceId
     * @param color
     * @param loginUser
     * @return
     */
    List<PictureVO> getPictureVOListByColor(Long spaceId,String color,User loginUser);

    /**
     * 为所有未设置图片主色调的图片设置主色调
     */
    void setPictureListColor();

    /**
     * 批量编辑图片
     * @param pictureEditByBatchRequest
     * @param loginUser
     */
    public void pictureEditByBatch(PictureEditByBatchRequest pictureEditByBatchRequest,User loginUser);

    /**
     * 创建Ai扩图任务
     * @param createPictureOutPaintingTaskRequest
     * @param loginUser
     */
    public CreateOutPaintingTaskResponse createPictureOutPaintTask(CreatePictureOutPaintingTaskRequest createPictureOutPaintingTaskRequest, User loginUser);


    /**
     * 复制图片到空间
     * @param source
     * @param targetSpaceId
     * @return
     */
    PictureVO copyPicture(Picture source, Long targetSpaceId,User loginUser);
}
